define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'lihua_private_req/index' + location.search,
                    add_url: '', //'lihua_private_req/add',
                    edit_url: '', //'lihua_private_req/edit',
                    del_url: '', //'lihua_private_req/del',
                    multi_url: 'lihua_private_req/multi',
                    table: 'lihua_private_req',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id')},
                        {field: 'mobile', title: __('Mobile')},
                        {field: 'city_name', title: __('City_name')},
                        {field: 'city_name_req', title: "申请城市"},
                        {field: 'type', title: "申请类型"},
                        {field: 'consignee', title: __('Consignee')},
                        {field: 'company', title: __('Company')},
                        {field: 'num', title: '用餐人数'},
                        {field: 'create_time', title: __('Create_time'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime},
                        {field: 'status', title: __('Status'), searchList: {"0":__('Status 0'),"1":__('Status 1')}, formatter: Table.api.formatter.status},
                        {field: 'remark', title: __('Remark')},
                        {
                            field: 'buttons',
                            title: "操作", 
                            events: {
                                'click .not_queryRefund': function (e, value, row, index) {
                                    //默认prompt
                                    layer.prompt({title: '请输入处理结果或者是否为无效请求', formType: 2},function(val, index){
                                        $.post("/api/index/private_req_do", { 'result': val, 'id': row.id }, function(data){
                                            layer.close(index);
                                            if(data.code==0){
                                                layer.msg(data.msg);
                                            }
                                            $(".btn-refresh").trigger("click");
                                        })
                                    });
                                    return false;
                                },
                            },
                            formatter : function (e, value, row, index) {
                                if (value.status=="0") {
                                    return '<span class="btn btn-default btn-xs btn-info not_queryRefund" style="margin-right:10px">处理</span>';
                                } else if (value.status=="1") {
                                    return '处理完毕';
                                }
                            }
                        },
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});